package com.xncoding.rocketmq.Controller;

import com.xncoding.rocketmq.entity.Order;
import com.xncoding.rocketmq.entity.User;
import com.xncoding.rocketmq.utils.RocketMqHelper;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class testController {

    /**
     * 日志
     */
    private static final Logger LOG = LoggerFactory.getLogger(testController.class);
    @Autowired
    private RocketMqHelper rocketMqHelper;

    //发送异步消息
    @GetMapping("asyncSend")
    public void asyncSend() {
        User person = new User();
        person.setName("java");
        person.setAge(18);
        rocketMqHelper.asyncSend("USER_ADD", MessageBuilder.withPayload(person).build());
    }


   //发送顺序消息
    @GetMapping("syncSendOrderly")
    public void syncSendOrderly() {
        Order order1 = new Order();
        Order order2 = new Order();
        Order order3 = new Order();
        Order order4 = new Order();
        order1.setOrderNO("1111111");
        order2.setOrderNO("2222222");
        order3.setOrderNO("3333333");
        order4.setOrderNO("4444444");


        order1.setOrderType("创建订单");
        rocketMqHelper.syncSendOrderly("ORDER_ADD", MessageBuilder.withPayload(order1).build(),order1.getOrderNO());

        order2.setOrderType("创建订单");
        rocketMqHelper.syncSendOrderly("ORDER_ADD", MessageBuilder.withPayload(order2).build(),order2.getOrderNO());

        order2.setOrderType("支付订单");
        rocketMqHelper.syncSendOrderly("ORDER_ADD", MessageBuilder.withPayload(order2).build(),order2.getOrderNO());

        order3.setOrderType("创建订单");
        rocketMqHelper.syncSendOrderly("ORDER_ADD", MessageBuilder.withPayload(order3).build(),order3.getOrderNO());


        order1.setOrderType("支付订单");
        rocketMqHelper.syncSendOrderly("ORDER_ADD", MessageBuilder.withPayload(order1).build(),order1.getOrderNO());

        order2.setOrderType("已发货");
        rocketMqHelper.syncSendOrderly("ORDER_ADD", MessageBuilder.withPayload(order2).build(),order2.getOrderNO());


        order3.setOrderType("支付订单");
        rocketMqHelper.syncSendOrderly("ORDER_ADD", MessageBuilder.withPayload(order3).build(),order3.getOrderNO());

        order2.setOrderType("已收货");
        rocketMqHelper.syncSendOrderly("ORDER_ADD", MessageBuilder.withPayload(order2).build(),order2.getOrderNO());


        order1.setOrderType("已发货");
        rocketMqHelper.syncSendOrderly("ORDER_ADD", MessageBuilder.withPayload(order1).build(),order1.getOrderNO());



        order4.setOrderType("创建订单");
        rocketMqHelper.syncSendOrderly("ORDER_ADD", MessageBuilder.withPayload(order4).build(),order4.getOrderNO());

        order3.setOrderType("已发货");
        rocketMqHelper.syncSendOrderly("ORDER_ADD", MessageBuilder.withPayload(order3).build(),order3.getOrderNO());

        order4.setOrderType("支付订单");
        rocketMqHelper.syncSendOrderly("ORDER_ADD", MessageBuilder.withPayload(order4).build(),order4.getOrderNO());

        order1.setOrderType("已收货");
        rocketMqHelper.syncSendOrderly("ORDER_ADD", MessageBuilder.withPayload(order1).build(),order1.getOrderNO());


        order4.setOrderType("已发货");
        rocketMqHelper.syncSendOrderly("ORDER_ADD", MessageBuilder.withPayload(order4).build(),order4.getOrderNO());


        order3.setOrderType("已收货");
        rocketMqHelper.syncSendOrderly("ORDER_ADD", MessageBuilder.withPayload(order3).build(),order3.getOrderNO());

        order4.setOrderType("已收货");
        rocketMqHelper.syncSendOrderly("ORDER_ADD", MessageBuilder.withPayload(order4).build(),order4.getOrderNO());


    }



}
